package com.project.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.LevelBean;
import com.project.bean.RoleBean;
import com.project.service.ILevelService;
import com.project.service.IRoleService;
import com.project.util.InfoResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lyl
 * description:
 */
@RestController
@RequestMapping("role")
@Api(tags = "角色相关controller")
public class RoleController {
    @Autowired
    private IRoleService iRoleService;
    @Autowired
    private ILevelService iLevelService;

    @GetMapping("showAllLevel")
    private List<LevelBean> findAllLev() {
        return iLevelService.showAll();
    }

    @GetMapping("showRoleByPage/{pageNum}")
    private Page<RoleBean> showRoleByPage(@PathVariable int pageNum) {
        return iRoleService.showRoleByPage(pageNum);
    }

    @GetMapping("showRoleById/{roleId}")
    private RoleBean showRoleById(@PathVariable int roleId) {
        return iRoleService.showRoleById(roleId);
    }

    @PostMapping("addRole/{roleName}/{levels}")
    private InfoResult addRole(@PathVariable String roleName, @PathVariable int[] levels) {
        return iRoleService.addRole(roleName, levels);
    }

    @GetMapping("showAllRole")
    private List<RoleBean> showAll() {
        return iRoleService.showAll();
    }

    @DeleteMapping("delRoleById/{roleId}")
    private InfoResult delRoleById(@PathVariable int roleId) {
        return iRoleService.delRoleById(roleId);
    }

    @PostMapping("updateRoleById/{roleId}/{levels}")
    private InfoResult updateRoleById(@PathVariable int roleId, @PathVariable int[] levels) {
        return iRoleService.updateRoleById(roleId, levels);
    }
}
